package Problem;

import java.util.Scanner;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/1/22.
// 
public class 扫雷 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int horizontal = scan.nextInt();
        int arrange = scan.nextInt();
        int[][] arr = new int[horizontal+2][arrange+2];
        int[][] flag = new int[horizontal+2][arrange+2];
        for (int i = 1; i <= horizontal; i++) {
            for (int j = 1; j <= arrange; j++) {
                arr[i][j] = scan.nextInt();
            }
        }
        for (int i = 1; i <= horizontal; i++) {
            for (int j = 1; j <= arrange; j++) {
                int count = 0;
                if(arr[i][j] == 1){
                    flag[i][j] = 9;
                }else {
                    if(arr[i-1][j-1] == 1)count++;
                    if(arr[i-1][j] == 1)count++;
                    if(arr[i-1][j+1] == 1)count++;
                    if(arr[i][j-1] == 1)count++;
                    if(arr[i][j+1] == 1)count++;
                    if(arr[i+1][j-1] == 1)count++;
                    if(arr[i+1][j] == 1)count++;
                    if(arr[i+1][j+1] == 1)count++;
                    flag[i][j] = count;
                    }
            }
        }
        for (int i = 1; i <= horizontal; i++) {
            for (int j = 1; j <= arrange; j++) {
                System.out.print(flag[i][j] + " ");
            }
            System.out.println();
        }
    }
}
